﻿Public Class Config

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Main.ListBox1.Items.Add("(" + DateTime.Now & ") - Browsing for serverconfig.txt...")
        OpenFileDialog1.Title = "Please Select the serverconfig.txt"
        OpenFileDialog1.FileName = "Choose File..."
        OpenFileDialog1.Filter = ".txt Files (*.txt)|*.txt|All Files (*.*)|*.*"
        OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\My Games\Terraria"
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        Dim oreader As New IO.StreamReader(OpenFileDialog1.FileName)
        TextBox1.Text = oreader.ReadToEnd
        oreader.Close()
        Button1.Enabled = True
        Main.ListBox1.Items.Add("(" + DateTime.Now & ") - serverconfig.txt Detected")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Main.ListBox1.Items.Add("(" + DateTime.Now & ") - Saving serverconfig.txt...")
        SaveFileDialog1.Title = "Save the Edited serverconfig.txt"
        SaveFileDialog1.FileName = "serverconfig.txt"
        SaveFileDialog1.Filter = ".txt File (*.txt)|*.txt"
        SaveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\My Games\Terraria"
        SaveFileDialog1.ShowDialog()
    End Sub

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        Dim objwriter As New System.IO.StreamWriter(SaveFileDialog1.FileName)
        objwriter.Write(TextBox1.Text)
        objwriter.Close()
        Main.ListBox1.Items.Add("(" + DateTime.Now & ") - serverconfig.txt Save Successful")
        TextBox1.Text = ""
        Button1.Enabled = False
        Me.Hide()
    End Sub

    Private Sub Config_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Enabled = False
    End Sub
End Class